package art_of_java_concurrent_programming.lock.condition;

/**
 * @author lixiangke
 * @date 2018/1/30
 */
public class BoundedQueueTest {
    public static void main(String[] args) throws InterruptedException {
        BoundedQueue<Integer> queue = new BoundedQueue<>(3);

        Thread t1 = new Thread() {
            @Override
            public void run() {
                try {
                    queue.add(1);
                    queue.add(2);
                    queue.add(3);
                    queue.add(4);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        };

        Thread t2 = new Thread() {
            @Override
            public void run() {
                try {
                    queue.remove();
                    queue.remove();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        };

        Thread t3 = new Thread() {
            @Override
            public void run() {
                try {
                    queue.add(5);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        };

        Thread t4 = new Thread() {
            @Override
            public void run() {
                try {
                    queue.add(6);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        };

        t1.start();
        t2.start();
        t3.start();

    }
}
